package top.go2do.goods.business.goods.module;

import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/6/18 11:07
 */
@Entity
@Table(name = "goods", uniqueConstraints = {
        @UniqueConstraint(name = "idx_unique_app_code_name", columnNames ={"app_id", "goods_code", "goods_name"})
})
@Data
public class GoodsPO {
    @Id
    @Column(name = "goods_id", columnDefinition = "BIGINT UNSIGNED COMMENT '实体ID(雪花算法分布式ID)'")
    private Long goodsId;

    @Column(name = "app_id", nullable = false, columnDefinition = "VARCHAR(32) COMMENT '所属应用ID'")
    private String appId;

    @Column(name = "goods_code", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '实体编码（每个应用内唯一）'")
    private String goodsCode;

    @Column(name = "goods_name", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '实体名称（每个应用内唯一）'")
    private String goodsName;

    @Column(name = "category_id", columnDefinition = "BIGINT UNSIGNED DEFAULT NULL COMMENT '所属分类的ID'")
    private String categoryId;

    @Column(name = "description", columnDefinition = "VARCHAR(255) COMMENT '标签描述'")
    private String description;

    @Column(name = "version", nullable = false, columnDefinition = "VARCHAR(64) COMMENT '版本号(由SHA-1 哈希算法生成)'")
    private String version;

    @Column(name = "sort", columnDefinition = "INT DEFAULT '1' COMMENT '排序权重'")
    private Integer sort;

    @Column(name = "status", nullable = false, columnDefinition = "TINYINT UNSIGNED DEFAULT 1 COMMENT '1正常,2冻结'")
    private Integer status;

    @Column(name = "json_config", nullable = false, columnDefinition = "VARCHAR(10000) DEFAULT '' COMMENT '其他配置（以json字符串存储，例如路由地址、图标名等）'")
    private String jsonConfig;

    @Column(name = "created_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间'")
    private LocalDateTime createdAt;

    @Column(name = "created_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '创建者'")
    private Long createdBy;

    @Column(name = "updated_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间'")
    private LocalDateTime updatedAt;

    @Column(name = "updated_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '更新者'")
    private Long updatedBy;
}
